/*
 * #%L
 * Admin
 * %%
 * Copyright (C) 2011 Ractoc.com
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package com.ractoc.opengamefinder.admin.plugins.messages;

import com.ractoc.opengamefinder.api.results.LoginMessageResult;
import com.ractoc.opengamefinder.api.results.MessageResultsErrorCodes;
import com.ractoc.opengamefinder.client.plugins.nifty.ScreenType;
import com.ractoc.pffj.api.BasePluginMessageResult;
import com.ractoc.pffj.api.PluginMessage;
import org.apache.log4j.Logger;

/**
 *
 * @author ractoc
 */
public class AccountPlugin extends com.ractoc.opengamefinder.client.plugins.AccountPlugin {
    
    private static Logger logger = Logger.getLogger(AccountPlugin.class.getName());
    
    private final String STATS_SCREEN = "STATS";
    
    /**
     * {@inheritDoc}
     */
    @Override
    protected BasePluginMessageResult loggedIn(final PluginMessage msg) {
        final BasePluginMessageResult result = new LoginMessageResult();
        final LoginMessageResult rMsg = (LoginMessageResult) msg;
        if (rMsg.getErrorCode() == MessageResultsErrorCodes.SUCCESS) {
            setAccount(rMsg.getAccountVO());
            logger.info("Logged in successfully.");
            displayScreen(STATS_SCREEN, ScreenType.STATS);
        } else {
            logger.info("Not logged in successfully.");
            displayError(rMsg.getErrorCode(), ScreenType.LOGIN);
        }
        return result;
    }
}
